#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{

	int n;
	cin >> n;
	
	for (int i = 0;i < n;i++) {
		long long ans = 0;
		string str;
		int tmp, l;
		cin >> l >> str;
		l--;
		for (int j = 0;j <l/2+1;j++) {
			if (str[j] != 'A' && str[j] != 'T' && str[j] != 'C' && str[j] != 'G' &&
				str[l - j] != 'A' && str[l - j] != 'T' && str[l - j] != 'C' && str[l - j] != 'G') {
				cout << 0 << endl;
				goto end;
			}
			if (str[j] == 'A' && str[l - j] == 'T' || str[j] == 'T' && str[l - j] == 'A' ||
				str[j] == 'C' && str[l - j] == 'G' || str[j] == 'G' && str[l - j] == 'C') {
				ans += (j + 1);
				ans += (l - j + 1);
			}			
		}
		cout << ans << endl;
	end:;
	}
	
	return 0;
}